package org.come.until;

import com.tool.btn.ShaoXiangBtn;
import org.come.Frame.ZhuFrame;
import org.come.Jpanel.ShaoXiangJpanel;
import org.come.entity.Goodstable;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;

import javax.swing.*;
import java.math.BigDecimal;

public class BarProgress extends Thread
{
    public JProgressBar progressBar;
    public ShaoXiangBtn shaoXiangBtn;
    public ShaoXiangJpanel shaoXiangJpanel;
    //进度条上的数字
    int[] progressValues={5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100};
    public BarProgress(JProgressBar progressBar,ShaoXiangBtn button,ShaoXiangJpanel shaoXiangJpanel)
    {
        this.progressBar=progressBar;
        this.shaoXiangBtn=button;
        this.shaoXiangJpanel = shaoXiangJpanel;
    }
    public void run()
    {
        shaoXiangBtn.setEnabled(false);
        for(int i=0;i<progressValues.length;i++)
        {
            try
            {
                Thread.sleep(500);
            }
            catch(InterruptedException e)
            {
                e.printStackTrace();
            }
            //设置进度条的值
            progressBar.setValue(progressValues[i]);
        }
        progressBar.setIndeterminate(false);
        //progressBar.setString("完成！");
        shaoXiangBtn.setEnabled(true);

        Goodstable goodstable = UserMessUntil.getgoodstable(new BigDecimal(90002));
        Goodstable rgoodstable = GoodsListFromServerUntil.chaxunsNew(goodstable.getGoodsid().intValue());
        String val =  shaoXiangJpanel.getChooseLeft().getText();
        if( shaoXiangJpanel.getChooseLeft().getText().startsWith("装备特技")){
            String val2 =  shaoXiangJpanel.getChooseItemLeft().getText();
            int p = 0;
            if(val2!=null){     //武器","帽子","项链","衣服","护符","鞋子
                if(val2 == "武器"){
                    p = 0;
                }else if(val2 == "帽子"){
                    p = 1;
                }else if(val2 == "项链"){
                    p = 2;
                }else if(val2 == "衣服"){
                    p = 3;
                }else if(val2 == "护身符"){
                    p = 4;
                }else if(val2 == "鞋子"){
                    p = 5;
                }
            }
            Goodstable choosegoods = GoodsListFromServerUntil.getChoseGoodsList()[p];
            if(choosegoods!=null){
                String sendmes = Agreement.getAgreement().shaoxiangAgreement(val+"|"+rgoodstable.getRgid()+"|"+val2+"|"+choosegoods.getRgid());
                SendMessageUntil.toServer(sendmes);
            }else{
                ZhuFrame.getZhuJpanel().addPrompt2("该位置没有穿戴装备");
            }
        }else{
            String sendmes = Agreement.getAgreement().shaoxiangAgreement(val+"|"+rgoodstable.getRgid());
            SendMessageUntil.toServer(sendmes);
        }
    }
}
